package com.seckill.vo;

import java.util.Objects;

/**
 * @author yangjunwei
 * @date 2021/7/3 上午12:40
 */
public enum OrderTypeEnum {

    /**
     * 订单类型
     */
    ORDINARY_ORDER(1, "普通订单", 600L),
    PEAK_ORDER(2, "高峰订单", 300L);

    private static final Long defaultTime = 30 * 60L;

    /**
     * 订单类型
     */
    private final Integer orderType;
    /**
     * 订单类型名称
     */
    private final String name;
    /**
     * 限时支付时间(s)
     */
    private final Long time;

    OrderTypeEnum(Integer orderType, String name, Long time) {
        this.orderType = orderType;
        this.name = name;
        this.time = time;
    }

    public Integer getOrderType() {
        return orderType;
    }

    public String getName() {
        return name;
    }

    public Long getTime() {
        return time;
    }

    public static Long getTime(Integer orderType) {
        OrderTypeEnum[] orderTypeEnums = OrderTypeEnum.values();
        for (OrderTypeEnum orderTypeEnum : orderTypeEnums) {
            if (Objects.equals(orderTypeEnum.orderType, orderType)) {
                return orderTypeEnum.time;
            }
        }
        return defaultTime;
    }


}
